﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.BaseCode;

namespace Web
{
    public partial class Blog : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.ArticleClass();
            this.NewArticle();
            this.ArticleTags();
        }

        /// <summary>
        /// 显示文章分类
        /// </summary>
        private void ArticleClass()
        {
            System.Data.DataSet ds = CommValue.SideBarClass;

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.RepeaterClass.DataSource = ds;
                this.RepeaterClass.DataBind();
            }
        }

        /// <summary>
        /// 显示文章标签
        /// </summary>
        private void ArticleTags()
        {
            System.Data.DataSet ds = CommValue.SideBarTag;

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.RepeaterTags.DataSource = ds;
                this.RepeaterTags.DataBind();
            }
        }

        /// <summary>
        /// 最近文章
        /// </summary>
        private void NewArticle()
        {
            System.Data.DataSet ds = CommValue.SideNewArticle;

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.RepeaterNewArticle.DataSource = ds;
                this.RepeaterNewArticle.DataBind();
            }
        }

        /// <summary>
        /// 最新文章绑定事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void RepeaterNewArticle_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                System.Data.DataRowView rowv = (System.Data.DataRowView)e.Item.DataItem;
                string ename = rowv["ename"].ToString();
                Literal ltr_newArticle = e.Item.FindControl("ltr_newArticleUrl") as Literal;
                ltr_newArticle.Text = CommMethod.GetUrl(BlogPageType.Article, ename);
            }
        }

        /// <summary>
        /// 文章分类绑定事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void RepeaterClass_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                System.Data.DataRowView rowv = (System.Data.DataRowView)e.Item.DataItem;
                string ename = rowv["ename"].ToString();
                Literal ltr_ArticleClassUrl = e.Item.FindControl("ltr_ArticleClassUrl") as Literal;
                ltr_ArticleClassUrl.Text = CommMethod.GetUrl(BlogPageType.Category, ename);
            }
        }

        /// <summary>
        /// 文章分类绑定事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void RepeaterTags_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                System.Data.DataRowView rowv = (System.Data.DataRowView)e.Item.DataItem;
                string ename = rowv["ename"].ToString();
                Literal ltr_ArticleClassUrl = e.Item.FindControl("ltr_ArticleClassUrl") as Literal;
                ltr_ArticleClassUrl.Text = CommMethod.GetUrl(BlogPageType.Tag, ename);
            }
        }
    }
}